<template>
    <div>
        <Card style="width:100%;">
			<p slot="title">
				公共设置
			</p>
			<div>
				<Row>
					<Col span="6">
						<Form label-position="right" :label-width="100">
							<FormItem label="基础币种：">
								<Input v-model="publicSetting.basicbz"></Input>
							</FormItem>
						</Form>
					</Col>
					<Col span="6">
						<Form label-position="right" :label-width="100">
							<FormItem label="计价币种：">
								<Input v-model="publicSetting.jjbz"></Input>
							</FormItem>
						</Form>
					</Col>
					<Col span="6">
						<Form label-position="right" :label-width="100">
							<FormItem label="最小买入：">
								<Input v-model="publicSetting.zxmr"></Input>
							</FormItem>
						</Form>
					</Col>
					<Col span="6">
						<Form label-position="right" :label-width="100">
							<FormItem label="最小盈利：">
								<Input v-model="publicSetting.zxyl"></Input>
							</FormItem>
						</Form>
					</Col>
					<Col span="6">
						<Form label-position="right" :label-width="100">
							<FormItem label="最大买入：">
								<Input v-model="publicSetting.zdmr"></Input>
							</FormItem>
						</Form>
					</Col>
					<Col span="6">
						<Form label-position="right" :label-width="100">
							<FormItem label="吃单概率：">
								<Input v-model="publicSetting.cdgl"></Input>
							</FormItem>
						</Form>
					</Col>
					<Col span="6">
						<Form label-position="right" :label-width="100">
							<FormItem label="交易对：">
								<span>{{publicSetting.jyd}}</span>
							</FormItem>
						</Form>
					</Col>
					<Col span="6">
						<Form label-position="right" :label-width="35">
							<FormItem label="">
								<CheckboxGroup v-model="publicSetting.openwebsocket">
									<Checkbox label="开启websocket"></Checkbox>
									
								</CheckboxGroup>
								
							</FormItem>
						</Form>
					</Col>
					<Col span="6">
						<Form label-position="right" :label-width="100">
							<FormItem label="">
								<RadioGroup v-model="publicSetting.wait" vertical>
									<Radio label="等待成交">等待成交</Radio>
								</RadioGroup>
							</FormItem>
						</Form>
					</Col>
					<Col span="6">
						<Form label-position="right" :label-width="120">
							<FormItem label="信号确认时间(ms):">
								<InputNumber :min="1" v-model="publicSetting.sureTime" style="width:100%;"></InputNumber>
							</FormItem>
						</Form>
					</Col>
					<Col span="6">
						<Form label-position="right" :label-width="100">
							<FormItem label="滑点级数:">
								<Select v-model="publicSetting.hdjs">
									<Option v-for="(item,key) in hdjslist" :value="item" :key="key">{{item}}</Option>
								</Select>
							</FormItem>
						</Form>
					</Col>
					<Col span="6">
						<div style="width:100%;height:57px;"></div>
					</Col>
					<Col span="6">
						<Form label-position="right" :label-width="100">
							<FormItem label="">
								<RadioGroup v-model="publicSetting.wait" vertical>
									<Radio label="挂单平仓">挂单平仓</Radio>
								</RadioGroup>
							</FormItem>
						</Form>
					</Col>
					<Col span="6">
						<Form label-position="right" :label-width="120">
							<FormItem label="挂单等待时间(秒):">
								<InputNumber :min="1" v-model="publicSetting.gdwait" style="width:100%;"></InputNumber>
							</FormItem>
						</Form>
					</Col>
				</Row>
				<div style="padding-left:30px;">
					市场连续冻结
					<InputNumber :min="1" v-model="publicSetting.djds"></InputNumber>
					单后，延时
					<InputNumber :min="1" v-model="publicSetting.ysjy"></InputNumber>
					秒不进行交易
				</div>
			</div>
		</Card>
		
		<Card style="width:100%;margin-top:15px;">
			<p slot="title">
				买方市场
			</p>
			<div>
				<Row>
					<Col span="6">
						<Form label-position="right" :label-width="100">
							<FormItem label="交易所:">
								<Select v-model="mfsc.jys">
									<Option v-for="(item,key) in jyslist" :value="item" :key="key">{{item}}</Option>
								</Select>
							</FormItem>
						</Form>
					</Col>
				</Row>
				<Row>
					<Col span="6">
						<Form label-position="right" :label-width="100">
							<FormItem label="API Key:">
								<Input v-model="mfsc.apikey"></Input>
							</FormItem>
						</Form>
					</Col>
					<Col span="6">
						<Form label-position="right" :label-width="100">
							<FormItem label="Secret Key:">
								<Input v-model="mfsc.Secret"></Input>
							</FormItem>
						</Form>
					</Col>
					<Col span="6">
						<Button type="primary" @click="Test(0)" style="margin-left:20px;">测试</Button>
					</Col>
				</Row>
				<Row>
					<Col span="6">
						<Form label-position="right" :label-width="100">
							<FormItem label="手续费(%):">
								<InputNumber :min="0" v-model="mfsc.sxf" style="width:100%;"></InputNumber>
							</FormItem>
						</Form>
					</Col>
					<Col span="6">
						<Form label-position="right" :label-width="100">
							<FormItem label="最大持有:">
								<InputNumber :min="0" v-model="mfsc.zdcy" style="width:100%;"></InputNumber>
							</FormItem>
						</Form>
					</Col>
				</Row>
			</div>
		</Card>
		
		<Card style="width:100%;margin-top:15px;">
			<p slot="title">
				卖方市场
			</p>
			<div>
				<Row>
					<Col span="6">
						<Form label-position="right" :label-width="100">
							<FormItem label="交易所:">
								<Select v-model="mfsc_1.jys">
									<Option v-for="(item,key) in jyslist" :value="item" :key="key">{{item}}</Option>
								</Select>
							</FormItem>
						</Form>
					</Col>
				</Row>
				<Row>
					<Col span="6">
						<Form label-position="right" :label-width="100">
							<FormItem label="API Key:">
								<Input v-model="mfsc_1.apikey"></Input>
							</FormItem>
						</Form>
					</Col>
					<Col span="6">
						<Form label-position="right" :label-width="100">
							<FormItem label="Secret Key:">
								<Input v-model="mfsc_1.Secret"></Input>
							</FormItem>
						</Form>
					</Col>
					<Col span="6">
						<Button type="primary" @click="Test(1)" style="margin-left:20px;">测试</Button>
					</Col>
				</Row>
				<Row>
					<Col span="6">
						<Form label-position="right" :label-width="100">
							<FormItem label="手续费(%):">
								<InputNumber :min="0" v-model="mfsc_1.sxf" style="width:100%;"></InputNumber>
							</FormItem>
						</Form>
					</Col>
					<Col span="6">
						<Form label-position="right" :label-width="100">
							<FormItem label="最大持有:">
								<InputNumber :min="0" v-model="mfsc_1.zdcy" style="width:100%;"></InputNumber>
							</FormItem>
						</Form>
					</Col>
				</Row>
			</div>
		</Card>
		<div style="width:100%;text-align:center;margin-top:15px;">
			<Button type="primary" style="margin-right:15px;" @click="saveSetting">保存设置</Button>
			<Button @click="cancel">取消设置</Button>
		</div>
		
    </div>
</template>
<script>
import { ipcRenderer } from 'electron';
export default {
    data(){
		return {
			jyslist:['huobi','bigone'],
			hdjslist:['1','2'],
			publicSetting:{
				basicbz:'EOS',
				jjbz:'candy',
				zxmr:'10',
				zxyl:'1000',
				zdmr:'100',
				cdgl:'55%',
				jyd:'iosteth',
				openwebsocket:[],
				wait:'',
				sureTime:1,
				hdjs:'',
				djds:1,
				ysjy:1,
				gdwait:1
			},
			mfsc:{
				jys:'',
				apikey:'',
				Secret:'',
				sxf:0,
				zdcy:0
			},
			mfsc_1:{
				jys:'',
				apikey:'',
				Secret:'',
				sxf:0,
				zdcy:0
			}
		}
	},
	created(){
		ipcRenderer.on('gethedginginfo',(event,message) => {
			this.jyslist = message.jyslist;
			this.hdjslist = message.hdjslist;
			this.publicSetting = message.publicSetting;
			this.mfsc = message.mfsc;
			this.mfsc_1 = message.mfsc_1;
		});
		this.getMessage('gethedginginfo','gethedginginfo');
		
		ipcRenderer.on('sethedginginfo',(event,message) => {
			console.log("设置")
			if(message=='ok'){
				this.$Message.success('设置成功');
				this.$router.push({name:'hedginginfo_1'});
			}
		});
	},
	methods:{
		getMessage:function(event,type){
			ipcRenderer.send(event,type);
	    },
		saveSetting:function(){
			this.getMessage('sethedginginfo',{publicSetting:this.publicSetting,mfsc:this.mfsc,mfsc_1:this.mfsc_1});
		},
		cancel:function(){
			this.$router.push({name:'hedginginfo_1'});
		},
		Test:function(num){
			if(num === 1){
				if(this.mfsc_1.apikey === ''){
					this.$Message.error('请填写API Key');
					return false;
				}
				if(this.mfsc_1.Secret === ''){
					this.$Message.error('请填写Secret Key');
					return false;
				}
				this.$Message.success('测试卖方市场成功');
			}else if(num===0){
				if(this.mfsc.apikey === ''){
					this.$Message.error('请填写API Key');
					return false;
				}
				if(this.mfsc.Secret === ''){
					this.$Message.error('请填写Secret Key');
					return false;
				}
				this.$Message.success('测试买方市场成功');
			}
		}
	},
	destroyed(){
		ipcRenderer.removeAllListeners('sethedginginfo');
		ipcRenderer.removeAllListeners('gethedginginfo');
	}
}
</script>
<style scoped>

</style>
